package com.joolun.web.api.forumtype.controller;

import java.util.List;

import com.joolun.common.annotation.Anonymous;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.web.api.forumtype.domain.ForumType;
import com.joolun.web.api.forumtype.service.IForumTypeService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 帖子分区配置Controller
 * 
 * @author joolun
 * @date 2025-04-12
 */
@RestController
@RequestMapping("/api/forumType")
@Anonymous
public class ForumTypeController extends BaseController
{
    @Autowired
    private IForumTypeService forumTypeService;

    /**
     * 查询帖子分区配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ForumType forumType)
    {
        startPage();
        List<ForumType> list = forumTypeService.selectForumTypeList(forumType);
        return getDataTable(list);
    }

    /**
     * 导出帖子分区配置列表
     */
    @Log(title = "帖子分区配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumType forumType)
    {
        List<ForumType> list = forumTypeService.selectForumTypeList(forumType);
        ExcelUtil<ForumType> util = new ExcelUtil<ForumType>(ForumType.class);
        util.exportExcel(response, list, "帖子分区配置数据");
    }

    /**
     * 获取帖子分区配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(forumTypeService.selectForumTypeById(id));
    }

    /**
     * 新增帖子分区配置
     */
    @Log(title = "帖子分区配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumType forumType)
    {
        return toAjax(forumTypeService.insertForumType(forumType));
    }

    /**
     * 修改帖子分区配置
     */
    @Log(title = "帖子分区配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumType forumType)
    {
        return toAjax(forumTypeService.updateForumType(forumType));
    }

    /**
     * 删除帖子分区配置
     */
    @Log(title = "帖子分区配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(forumTypeService.deleteForumTypeByIds(ids));
    }
}
